package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingPlanController
 * @Author lifuyun
 * @Date 2024-08-27
 */
@RestController
@RequestMapping("/nursing/plan")
@Slf4j
@Api(tags = "护理计划管理")
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     *
     * @return
     */
    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>> getAllNursingPlan() {
        log.info("处理查询所有护理计划的请求");
        List<NursingPlanVo> list = nursingPlanService.getAllNursingPlan();
        return success(list);
    }

    /**
     * 新增护理计划
     *
     * @param nursingPlanDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理计划")
    @ApiImplicitParam(name = "nursingPlanDto", value = "护理计划数据传输对象", required = true)
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        log.info("处理新增护理计划请求，请求参数：{}", nursingPlanDto);
        nursingPlanService.addNursingPlan(nursingPlanDto);

        return success();
    }

    /**
     * 条件分页查询护理计划
     *
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/search")
    @ApiOperation("分页查询护理计划列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "护理计划名称"),
            @ApiImplicitParam(name = "status", value = "状态"),
            @ApiImplicitParam(name = "pageNum", value = "页码（默认为1）", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页大小（默认为10）", required = true)
    })
    public ResponseResult<PageResponse<NursingPlanVo>> getByPage(
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(value = "status", required = false) Integer status

    ) {
        log.info("处理分页查询护理计划列表请求，请求参数：name={},pageNum={},pageSize={},status={}", name, pageNum, pageSize, status);
        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.getByPage(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingPlanVo> getById(
            @ApiParam(value = "护理计划id", required = true) @PathVariable Long id) {
        log.info("处理根据id查询护理计划请求，请求参数：id={}", id);
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return success(nursingPlanVo);
    }

    /**
     * 修改护理计划
     *
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation("修改护理计划")
    @ApiImplicitParam(name = "nursingPlanDto", value = "护理计划数据传输对象", required = true)
    public ResponseResult updateById(@RequestBody NursingPlanDto nursingPlanDto) {
        log.info("处理修改护理计划请求，请求参数：{}", nursingPlanDto);
        nursingPlanService.updateById(nursingPlanDto);
        return success();
    }

    /**
     * 删除护理计划
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    @ApiImplicitParam(name = "id", value = "护理计划id", required = true)
    public ResponseResult deleteById(@PathVariable Long id) {
        log.info("处理删除护理计划请求，请求参数：id={}", id);
        nursingPlanService.deleteById(id);

        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用护理计划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "护理计划ID", required = true),
            @ApiImplicitParam(name = "status", value = "状态：0-禁用，1-启用", required = true)})
    public ResponseResult updateNursingPlanStatus(@PathVariable long id, @PathVariable int status) {

        log.info("处理启用禁用护理计划请求，请求参数：id={}，status={}", id, status);
        nursingPlanService.updateNursingPlanStatus(id,status);
        return success();
    }
}
